/*
 * Copyright 2012 the original author or authors.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package org.chacha.entity;

import java.io.IOException;

import org.chacha.model.LoginToken;
import org.chacha.util.JsonPojoMapper;

import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.databind.JsonMappingException;

/**
 * 密码认证回应消息
 *	@author: hejing
 *	@date: 2012-11-22-下午03:15:45
 */
public class AuthResponse extends Response{
	private String token;

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public static void main(String[] args) throws JsonMappingException, JsonGenerationException, IOException{
		//认证成功回应消息
		AuthResponse entity=new AuthResponse();
		entity.setResult(ResponseCode.SUCCESS);
		
		LoginToken token=new LoginToken("chacha");
		entity.setToken(token.getToken());
		try{
	        String pojoAsString = JsonPojoMapper.toJson(entity, true);
	        System.out.println( pojoAsString );
	        AuthResponse pojo = (AuthResponse) JsonPojoMapper.fromJson(pojoAsString, AuthResponse.class);

	        //认证失败回应消息
	        AuthResponse response=new AuthResponse();
	        response.setResult(ResponseCode.ERROR_USERPASS);
	        pojoAsString = JsonPojoMapper.toJson(response, true);
	        System.out.println( pojoAsString );
	        //空回应消息
	        response=new AuthResponse();
	        pojoAsString = JsonPojoMapper.toJson(response, true);
	        System.out.println( pojoAsString );
		}catch(Exception e){
			e.printStackTrace();
		}
	}

}
